home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Data Manipulation / Delete Marquee Points < prev    next >
Text File  |  1996-01-29  |  9KB  |  244 lines

  1. | Version 1.01, 5/17/94
  2. |    Used Wave/D instead of Wave in several places.
  3.  
  4. | Version 1.10, 12/31/95. Update for Igor Pro 3.0.
  5. |    Got rid of /D which is no longer needed.
  6.  
  7. #pragma rtGlobals = 1
  8.  
  9. | DeletePointsXY(deleteMode, isParametric, theXWave, theYWave, startPoint, endPoint, minY, maxY)
  10. |    Deletes points that fit criteria determined by deleteMode and checkMode
  11. |    See DeleteMarqueeData for an explanation of deleteMode.
  12. |    If isParametric is non-zero then theXWave is the wave against which theYWave is graphed.
  13.  
  14. Function DeletePointsXY(deleteMode, isParametric, theXWave, theYWave, startPoint, endPoint, minY, maxY)
  15.     Variable deleteMode                    | 1 for delete inside marquee, 2 for delete outside
  16.     Variable isParametric
  17.     Wave theXWave, theYWave
  18.     Variable startPoint, endPoint
  19.     Variable minY, maxY
  20.     
  21.     Variable numToCheck
  22.     Variable p, numDeleted, deleteIt
  23.     Variable val
  24.     
  25.     numDeleted = 0
  26.     numToCheck = endPoint-startPoint+1
  27.     if (numToCheck <= 0)
  28.         return 0
  29.     endif
  30.     p = startPoint
  31.     do
  32.         val = theYWave[p]
  33.         if (deleteMode == 1)
  34.             deleteIt = (val >= minY) %& (val <= maxY)    | deleting inside points
  35.         else    
  36.             deleteIt = (val < minY) %| (val > maxY)        | deleting outside points
  37.         endif
  38.         if (deleteIt)
  39.             DeletePoints p, 1, theYWave
  40.             if (isParametric)
  41.                 DeletePoints p, 1, theXWave
  42.             endif
  43.             numDeleted += 1
  44.         else
  45.             p += 1
  46.         endif
  47.         numToCheck -= 1
  48.     while (numToCheck > 0)
  49. End
  50.  
  51. Function FDeleteMarqueeData(yWave, deleteMode, checkMode)
  52.     Wave yWave
  53.     Variable deleteMode            // 1 = delete inside marquee, 2 = delete outside marquee
  54.     Variable checkMode            // 1 = check X values, 2 = check Y values, 3 = check X and Y values
  55.  
  56.     Variable minPoint, maxPoint, numToDeleteFromEnd, numDeleted, len
  57.     Variable minY, maxY, val
  58.     Variable isParametricPlot        | 1 if normal, 2 if parametric (XY)
  59.     
  60.     | find the wave against which yWave is plotted, if any
  61.     Wave xWave = XWaveRefFromTrace("", NameOfWave(yWave))
  62.     isParametricPlot = WaveExists(xWave)
  63.     
  64.     if (checkMode %& 1)                        | do we care about X values ?
  65.         GetMarquee bottom                    | find horizontal marquee location is in terms of the bottom axis
  66.         if (isParametricPlot)
  67.             FindLevel/Q xWave, V_left
  68.             if (V_Flag)
  69.                 minPoint = 0                            | V_left is less than the smallest value in xWave
  70.             else
  71.                 minPoint = x2pnt(xWave, V_LevelX)
  72.             endif
  73.             FindLevel/Q xWave, V_right
  74.             if (V_Flag)
  75.                 maxPoint = numpnts(xWave)-1        | V_right is greater than the largest value in xWave
  76.             else
  77.                 maxPoint = x2pnt(xWave, V_LevelX)
  78.             endif
  79.         else
  80.             minPoint = x2pnt(yWave, V_left)
  81.             maxPoint = x2pnt(yWave, V_right)
  82.         endif
  83.     else
  84.         minPoint = 0
  85.         maxPoint = numpnts(yWave)-1
  86.     endif
  87.     
  88.     if (checkMode %& 2)                | do we care about Y values ?
  89.         GetMarquee left                | find vertical marquee location is in terms of the left axis
  90.         minY = V_bottom
  91.         maxY = V_top
  92.     endif
  93.     
  94.     if (checkMode == 1)                | are we checking just X values ?
  95.         | Make sure that we are not trying to delete the entire wave
  96.         if (deleteMode == 1)
  97.             len = numpnts(yWave) - (maxPoint-minPoint+1)
  98.         else
  99.             len = maxPoint - minPoint - 1
  100.         endif
  101.     endif
  102.  
  103.     if (deleteMode == 1)            | deleting inside points ?
  104.         if (checkMode == 1)        | we are checking X values only ?
  105.             numDeleted = maxPoint-minPoint+1
  106.             DeletePoints minPoint, numDeleted, yWave
  107.             if (isParametricPlot)
  108.                 DeletePoints minPoint, numDeleted, xWave
  109.             endif
  110.             Printf "%d points deleted from %d to %d\r", numDeleted, minPoint, maxPoint
  111.         endif
  112.         if (checkMode %& 2)        | we need to check Y values ?
  113.             len = numpnts(yWave)                    | original number of points
  114.             DeletePointsXY(deleteMode, isParametricPlot, xWave, yWave, minPoint, maxPoint, minY, maxY)
  115.             numDeleted = len - numpnts(yWave)
  116.             Printf "%d points deleted\r", numDeleted
  117.         endif
  118.     endif
  119.     
  120.     if (deleteMode == 2)            | deleting outside points ?
  121.         numToDeleteFromEnd = numpnts(yWave) - maxPoint - 1
  122.         if (checkMode == 1)        | we are checking X values only ?
  123.             DeletePoints maxPoint+1, numToDeleteFromEnd, yWave
  124.             DeletePoints 0, minPoint, yWave
  125.             if (isParametricPlot)
  126.                 DeletePoints maxPoint+1, numToDeleteFromEnd, xWave
  127.                 DeletePoints 0, minPoint, xWave
  128.             endif
  129.             Printf "%d points deleted from start, %d points deleted from end\r", minPoint, numToDeleteFromEnd
  130.         endif
  131.         if (checkMode %& 2)        | we need to check Y values ?
  132.             len = numpnts(yWave)                    | original number of points
  133.             if (checkMode == 2)                        | checking Y values only ?
  134.                 DeletePointsXY(deleteMode, isParametricPlot, xWave, yWave, minPoint, maxPoint, minY, maxY)
  135.             else                                        | checking X and Y values
  136.                 numToDeleteFromEnd = numpnts(yWave) - maxPoint - 1
  137.                 DeletePoints maxPoint+1, numToDeleteFromEnd, yWave
  138.                 if (isParametricPlot)
  139.                     DeletePoints maxPoint+1, numToDeleteFromEnd, xWave
  140.                 endif
  141.                 DeletePointsXY(deleteMode, isParametricPlot, xWave, yWave, minPoint, maxPoint, minY, maxY)
  142.                 DeletePoints 0, minPoint, yWave
  143.                 if (isParametricPlot)
  144.                     DeletePoints 0, minPoint, xWave
  145.                 endif
  146.             endif
  147.             numDeleted = len - numpnts(yWave)
  148.             Printf "%d points deleted\r", numDeleted
  149.         endif
  150.     endif
  151.     
  152.     Printf "Length of data = %d\r", numpnts(yWave)
  153. End
  154.  
  155. | DeleteMarqueeData(theYWave, deleteMode, checkMode)
  156. |    This deletes points from the specified wave that is displayed against the
  157. |    bottom/left axes of the active graph.
  158. |
  159. |    In its simplest form, the technique is to create a marquee in the graph that
  160. |    encloses the points you want to delete and then run the macro. It will delete
  161. |    the marqueed points.
  162. |    To try this, do the following:
  163. |        Make test=gnoise(1); Display test; Modify mode=2, lsize=3
  164. |        (Now marquee some points and select DeleteMarqueeData from the Macros menu.)
  165. |
  166. |    There are several other ways to use it. These ways differ in the criteria
  167. |    used to select which points will be deleted.
  168. |        You can delete the points outside the marquee rather than inside.
  169. |
  170. |        You can delete points that fall inside or outside a given range of Y values,
  171. |        regardless of their X values.
  172. |
  173. |        You can delete points that fall inside or outside a given range of X values,
  174. |        regardless of their Y values. This is by far the fastest technique because it
  175. |        does not have to search point by point.
  176. |
  177. |    The deleteMode and checkMode parameters determine the criteria used when
  178. |    selecting points to delete.
  179. |
  180. |    If checkMode is 1, then only X values are tested.    (this will run quickly)
  181. |    If checkMode is 2 then only Y values are tested.    (this can be very time consuming)
  182. |    If checkMode is 3 then X and Y values are tested.    (this can be very time consuming)
  183. |
  184. |    deleteMode determines whether points inside the marquee or outside the marquee
  185. |    will be deleted.
  186. |    If deleteMode is 1 then inside points are deleted.
  187. |    If deleteMode is 2 then outside points are deleted.
  188. |
  189. |    The macro assumes that the wave is sorted and increasing in the X direction.
  190. |    If you are graphing an XY pair and if the X wave is not monotonically increasing,
  191. |    use the Sort operation to sort it.
  192. Proc DeleteMarqueeData(theYWave, deleteMode, checkMode) : GraphMarquee
  193.     String theYWave=WaveName("", 0, 1)        | name of the wave containing the Y values
  194.     Prompt theYWave, "Select the wave from which you want to delete", popup, WaveList("*", ";", "WIN:")
  195.     Variable deleteMode=NumVarOrDefault("root:Packages:'Delete Marquee Points':gDeleteMarqueeModeSave", 1)
  196.     Prompt deleteMode, "Delete", popup, "Points Inside Marquee;Points Outside Marquee"
  197.     Variable checkMode=NumVarOrDefault("root:Packages:'Delete Marquee Points':gDeleteMarqueeCheckModeSave", 3)
  198.     Prompt checkMode, "Criteria for selecting points to delete", popup, "X Values;Y Values;X and Y Values"
  199.  
  200.     PauseUpdate; Silent 1
  201.     
  202.     | Save input parameters for next time
  203.     NewDataFolder/O root:Packages
  204.     NewDataFolder/O root:Packages:'Delete Marquee Points'
  205.     Variable/G root:Packages:'Delete Marquee Points':gDeleteMarqueeModeSave = deleteMode
  206.     Variable/G root:Packages:'Delete Marquee Points':gDeleteMarqueeCheckModeSave = checkMode
  207.     
  208.     FDeleteMarqueeData($theYWave, deleteMode, checkMode)
  209. End
  210.  
  211. Proc DoDeleteMarqueeData()
  212.     if (WinType(WinName(0, -1)) != 1)            | check that target window is a graph
  213.         Abort "The target window must be a graph"
  214.     endif
  215.     
  216.     GetMarquee left                                    | check that a marquee is up
  217.     if (V_Flag == 0)
  218.         Abort "You must create a marquee before running this procedure"
  219.     endif
  220.     
  221.     DeleteMarqueeData()
  222. End
  223.  
  224. | Matrix of Conditions for DeleteMarqueeData
  225. |    Parametric data
  226. |        Delete Inside Points
  227. |            Check X Values
  228. |            Check Y Values
  229. |            Check X and Y Values
  230. |        Delete Outside Points
  231. |            Check X Values
  232. |            Check Y Values
  233. |            Check X and Y Values
  234. |    Normal data
  235. |        Delete Inside Points
  236. |            Check X Values
  237. |            Check Y Values
  238. |            Check X and Y Values
  239. |        Delete Outside Points
  240. |            Check X Values
  241. |            Check Y Values
  242. |            Check X and Y Values
  243.  
  244.